package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo01
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  17:03
 */
public class ServletConfigDemo01 extends HttpServlet {

    private ServletConfig servletConfig;

    // 两种获取servletConfig的方式
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 通过init初始化方法获取
        System.out.println(servletConfig);

        // 通过GenericServlet类获取ServletConfig对象
        ServletConfig config = getServletConfig();

        System.out.println(servletConfig);
        System.out.println(config);

    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        // 给成员属性赋值
        this.servletConfig = config;
    }
}
